home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / src / proxy / proxystrings.h < prev    next >
C/C++ Source or Header  |  2006-06-04  |  3KB  |  118 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. Please visit our Website: http://www.httrack.com
  21. */
  22.  
  23.  
  24. /* ------------------------------------------------------------ */
  25. /* File: Strings                                                */
  26. /* Author: Xavier Roche                                         */
  27. /* ------------------------------------------------------------ */
  28.  
  29. // Strings a bit safer than static buffers
  30.  
  31. #ifndef HTS_PROXYSTRINGS_DEFSTATIC
  32. #define HTS_PROXYSTRINGS_DEFSTATIC 
  33.  
  34. #include "htsstrings.h"
  35.  
  36.  
  37. /* Tools */
  38.  
  39. static int ehexh(char c) {
  40.   if ((c>='0') && (c<='9')) return c-'0';
  41.   if ((c>='a') && (c<='f')) c-=('a'-'A');
  42.   if ((c>='A') && (c<='F')) return (c-'A'+10);
  43.   return 0;
  44. }
  45.  
  46. static int ehex(const char* s) {
  47.   return 16*ehexh(*s)+ehexh(*(s+1));
  48. }
  49.  
  50. static void unescapehttp(const char* s, String* tempo) {
  51.   int i;
  52.   for (i = 0; s[i] != '\0' ; i++) {
  53.     if (s[i]=='%' && s[i+1]=='%') {
  54.       i++;
  55.       StringAddchar(*tempo, '%');
  56.     } else if (s[i]=='%') {
  57.       char hc;
  58.       i++;
  59.       hc = (char) ehex(s+i);
  60.       StringAddchar(*tempo, (char) hc);
  61.       i++;    // sauter 2 caractΦres finalement
  62.     }
  63.     else if (s[i]=='+') {
  64.       StringAddchar(*tempo, ' ');
  65.     }
  66.     else
  67.       StringAddchar(*tempo, s[i]);
  68.   }
  69. }
  70.  
  71. static void escapexml(const char* s, String* tempo) {
  72.   int i;
  73.   for (i=0 ; s[i] != '\0' ; i++) {
  74.     if (s[i] == '&')
  75.       StringCat(*tempo, "&");
  76.         else if (s[i] == '<')
  77.       StringCat(*tempo, "<");
  78.         else if (s[i] == '>')
  79.       StringCat(*tempo, ">");
  80.         else if (s[i] == '\"')
  81.       StringCat(*tempo, """);
  82.     else
  83.       StringAddchar(*tempo, s[i]);
  84.   }
  85. }
  86.  
  87. static char* concat(char *catbuff,const char* a,const char* b) {
  88.     if (a != NULL && a[0] != '\0') {
  89.         strcpy(catbuff, a);
  90.     } else {
  91.         catbuff[0] = '\0';
  92.     }
  93.     if (b != NULL && b[0] != '\0') {
  94.         strcat(catbuff, b);
  95.     }
  96.   return catbuff;
  97. }
  98.  
  99. static char* __fconv(char* a) {
  100. #ifdef WIN32
  101.   int i;
  102.   for(i = 0 ; a[i] != 0 ; i++)
  103.     if (a[i] == '/')  // Unix-to-DOS style
  104.       a[i] = '\\';
  105. #endif
  106.   return a;
  107. }
  108.  
  109. static char* fconcat(char *catbuff, const char* a, const char* b) {
  110.   return __fconv(concat(catbuff,a,b));
  111. }
  112.  
  113. static char* fconv(char *catbuff, const char* a) {
  114.   return __fconv(concat(catbuff,a,""));
  115. }
  116.  
  117. #endif
  118.